package blockchain.entity.block;

import ch.qos.logback.core.util.TimeUtil;
import org.springframework.beans.factory.annotation.Value;

import java.util.List;
import java.util.Random;

/**
 * @Author: 李浩然
 * @Date: 2020/12/23 10:29 下午
 */
public class BlockHeader {
    /**
     * 版本号
     */
    @Value("blockchain.version")
    private int version;
    /**
     * 上一个版本的哈希
     */
    private String hashPreviousBlock;
    /**
     * Merkle根哈希值
     */
    private String hashMerkleRoot;
    /**
     * 公钥
     */
    private String publicKey;
    /**
     * 区块序号
     */
    private int number;
    /**
     * 时间戳
     */
    private long timeStamp;
    /**
     * 32位随机种子
     */
    private long nonce;
    /**
     * 区块内交易的哈希集合，用于计算Merkle根Hash
     */
    private List<String> hashList;
    private Random rand = new Random();

    public BlockHeader() {
    }

    public BlockHeader(String hashPreviousBlock, String hashMerkleRoot, String publicKey, int number) {
        this.hashPreviousBlock = hashPreviousBlock;
        this.hashMerkleRoot = hashMerkleRoot;
        this.publicKey = publicKey;
        this.number = number;
        this.timeStamp = System.currentTimeMillis();
        this.nonce = rand.nextLong();
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public String getHashPreviousBlock() {
        return hashPreviousBlock;
    }

    public void setHashPreviousBlock(String hashPreviousBlock) {
        this.hashPreviousBlock = hashPreviousBlock;
    }

    public String getHashMerkleRoot() {
        return hashMerkleRoot;
    }

    public void setHashMerkleRoot(String hashMerkleRoot) {
        this.hashMerkleRoot = hashMerkleRoot;
    }

    public String getPublicKey() {
        return publicKey;
    }

    public void setPublicKey(String publicKey) {
        this.publicKey = publicKey;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public long getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(long timeStamp) {
        this.timeStamp = timeStamp;
    }

    public long getNonce() {
        return nonce;
    }

    public void setNonce(long nonce) {
        this.nonce = nonce;
    }

    public List<String> getHashList() {
        return hashList;
    }

    public void setHashList(List<String> hashList) {
        this.hashList = hashList;
    }
}
